﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MobileSales.Model.Params;
using System.Runtime.Serialization;
using MobileSales.Model.Util;
using MobileSales.Model.Localization;
using System.ComponentModel.DataAnnotations;

namespace MobileSales.Model.Clients
{
    [DataContract]
    public class Client : ParamObject
    {
        #region Public members
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        [Display(Name = "Group", ResourceType = typeof(ModelStrings))]
        public ClientGroup Group { get; set; }
        [DataMember]
        [Display(Name = "Name", ResourceType = typeof(ModelStrings))]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        public string Name { get; set; }
        [DataMember]
        [Display(Name = "Name2", ResourceType = typeof(ModelStrings))]
        public string Name2 { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Nip", ResourceType = typeof(ModelStrings))]
        public string Nip { get; set; }
        [DataMember]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [Display(Name = "Zipcode", ResourceType = typeof(ModelStrings))]
        public string Zipcode { get; set; }
        [DataMember]
        [Display(Name = "City", ResourceType = typeof(ModelStrings))]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        public string City { get; set; }
        [DataMember]
        [Display(Name = "Street", ResourceType = typeof(ModelStrings))]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        public string Street { get; set; }
        [DataMember]
        [Display(Name = "Phone", ResourceType = typeof(ModelStrings))]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        public string Phone { get; set; }
        [DataMember]
        [Display(Name = "Fax", ResourceType = typeof(ModelStrings))]
        public string Fax { get; set; }
        [DataMember]
        [Display(Name = "Info", ResourceType = typeof(ModelStrings))]
        public string Info { get; set; }
        [DataMember]
        [Display(Name = "Info2", ResourceType = typeof(ModelStrings))]
        public string Info2 { get; set; }
        [DataMember]
        [Display(Name = "Debts", ResourceType = typeof(ModelStrings))]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        [RegularExpression(RegExp.DoubleRegexp, ErrorMessageResourceName = "InvalidDouble", ErrorMessageResourceType = typeof(ValidationStrings))]
        public double Debts { get; set; }
        [DataMember]
        [Display(Name = "IsSupplier", ResourceType = typeof(ModelStrings))]
        public bool IsSupplier { get; set; }
        [DataMember(Name = "LastVisitTime")]
        private String _lastVisitTime { get; set; }

        [Display(Name = "LastVisitTime", ResourceType = typeof(ModelStrings))]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ValidationStrings))]
        public DateTime? LastVisitTime
        {
            get
            {
                if (_lastVisitTime != null) return DateUtil.Deserialize(_lastVisitTime);
                return null;
            }
            set
            {
                if (value.HasValue) _lastVisitTime = DateUtil.Serialize(value.Value);
                else _lastVisitTime = null;
            }
        }
        #endregion
    }
}
